from manimlib import *
from numpy import square
import numpy as np

class SquareToCircle(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    def construct(self):
        self.camera.background_color = WHITE
        axes = Axes(
            x_range=[0, 5, 1],
            y_range=[0, 5, 1],
            x_length=5,
            y_length=5,
            axis_config={
                "color": BLACK,
                "numbers_to_include": np.arange(0, 4.01, 1),
                },
            # tips=False,
        )
        self.add(axes.get_axis_labels())
        axes.x_axis.numbers.set_color(BLACK)
        axes.y_axis.numbers.set_color(BLACK)

        f1=axes.get_graph(lambda x:x+2,color='#75cfb8',x_range=[0,2])
        f2=axes.get_graph(lambda x:x-2,color='#ffc478',x_range=[2,4])

        dot1=Dot(color=RED).move_to(axes.c2p(0,4))
        dot2=Dot(color=RED).move_to(axes.c2p(4,4))
        dot3=Dot(color=RED).move_to(axes.c2p(4,0))
        self.add(Line(dot1.get_corner(ORIGIN),dot2.get_corner(ORIGIN)).set_color(BLACK),Line(dot3.get_corner(ORIGIN),dot2.get_corner(ORIGIN)).set_color(BLACK))
        self.add(Polygon(axes.coords_to_point(0,0),axes.coords_to_point(2,0),axes.coords_to_point(4,2),axes.coords_to_point(4,4),axes.coords_to_point(2,4),axes.coords_to_point(0,2),color=GRAY).set_fill(color=GRAY,opacity=0.5).set_stroke(opacity=0))

        self.add(axes.get_graph_label(f1,'y=x+2').shift(LEFT*3+DOWN*1.5),axes.get_graph_label(f2,'y=x-2').shift(LEFT+DOWN))
        self.add(axes,f1,f2)
        self.wait(0.03)